// ==UserScript==
// @name         Exhentai收藏快速移除
// @namespace    http://tampermonkey.net/
// @version      0.0.1-2024-12-24
// @description  try to take over the world!
// @author       You
// @match        https://exhentai.org/favorites.php*
// @icon         https://exhentai.org/favicon.ico
// @grant        GM_xmlhttpRequest
// @downloadURL https://gitee.com/AgMonk/tampermonkey-script/raw/master/ehentai/ehentai-favor-quick-remove.user.js
// @updateURL https://gitee.com/AgMonk/tampermonkey-script/raw/master/ehentai/ehentai-favor-quick-remove.user.js
// ==/UserScript==

(function() {
    'use strict';
    const delGallery = function(id){
        // 请求地址
        const url = window.location.href
        return GM_xmlhttpRequest({
            method: 'POST',
            url:  url,
            headers: {
                "Content-Type":"application/x-www-form-urlencoded"
            },
            data:`ddact=delete&modifygids%5B%5D=${id}`,
            onload: function(res){
                console.log(`已删除画廊 id = ${id}`)
                window.location.reload()
            },
        });
    }


    setInterval(()=>{
        // 画廊
        const galleries = [...document.getElementsByClassName('gl1t')]

        galleries.forEach(gallery=>{
            if (!gallery.quickDel){
                gallery.quickDel=true

                const url = gallery.getElementsByTagName('a')[0].href
                const id = parseInt(url.split('/')[4])

                const container = gallery.getElementsByClassName('gldown')[0]
                // const container = gallery.getElementsByClassName('gl5t')[0]

                const button = document.createElement('div')
                button.innerText = ' 删 '
                button.style.backgroundColor = 'red'
                button.style.borderRadius='15px'
                button.style.cursor='pointer'
                button.onclick = ()=> {
                    if (confirm('删除收藏')) delGallery(id)
                }

                container.appendChild(button)
            }
        })
    },2000)
})();